Fix boolean type mismatch on Windows when windows.h is included#240
Open
Senthil455 wants to merge 1 commit into
Open
Fix boolean type mismatch on Windows when windows.h is included#240Senthil455 wants to merge 1 commit into
Senthil455 wants to merge 1 commit into
Conversation
On Windows, the standard windows.h header defines 'boolean' as 'unsigned char' (1 byte), while jpeglib's jmorecfg.h defines it as 'int' (4 bytes) when HAVE_BOOLEAN is not defined. This causes a struct layout mismatch between the library and the application, triggering the size check error in jpegli_CreateDecompress. The fix adds a #ifdef _WIN32 block in include_jpeglib.h (which is included before jpeglib.h) that: - Defines boolean as unsigned char (matching Windows convention) - Sets HAVE_BOOLEAN to prevent jmorecfg.h from redefining it as int - Defines INT32 as signed int (not long) per Windows ABI convention - Sets XMD_H to prevent jmorecfg.h from redefining INT16/INT32 Also updates decode_internal.h and input.cc to include jpeglib.h through include_jpeglib.h so they also benefit from the Windows fix. This mirrors the upstream libjpeg-turbo fix in jconfig.h.in.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description
When a Windows application includes
windows.hbefore jpegli headers, thebooleantype is defined asunsigned char(1 byte) by the Windows RPC headers. However, libjpeg-turbo'sjmorecfg.hdefines it asint(4 bytes) whenHAVE_BOOLEANis not defined. This causes a struct layout mismatch injpeg_decompress_struct, triggering the size check error injpegli_CreateDecompress.Root Cause
The size check in
jpegli_CreateDecompress(atlib/jpegli/decode.cc:560) comparessizeof(*cinfo)computed by the library againstsizeof(struct jpeg_decompress_struct)computed by the caller. When the caller haswindows.hincluded, thebooleanfield is 1 byte, but the library compiled it as 4 bytes, so the sizes differ and the function errors out.Fix
Three files were modified:
lib/base/include_jpeglib.hAdded a
#ifdef _WIN32block before#include <jpeglib.h>that mirrors the upstream libjpeg-turbo fix fromjconfig.h.in:booleanasunsigned char(matching Windows convention) unless__RPCNDR_H__is already defined (avoiding conflict with Windows RPC headers)HAVE_BOOLEANto preventjmorecfg.hfrom redefiningbooleanasintINT32assigned int(notlong) per Windows ABI convention, guarded against_BASETSD_H_/_BASETSD_Hto avoid conflict with Windows headersXMD_Hto preventjmorecfg.hfrom redefiningINT16/INT32lib/jpegli/decode_internal.hChanged
#include "jpeglib.h"to#include "lib/base/include_jpeglib.h"so this internal header also gets the Windows fix applied (previously bypassed it).lib/jpegli/input.ccSame change as above — now goes through
include_jpeglib.hto ensure consistentbooleandefinition.Testing
jconfig.h.in#ifdef _WIN32block is a no-op, so there is no behavior change__RPCNDR_H__and_BASETSD_H_/_BASETSD_Hguards prevent conflicts with Windows system headersjpeglib.hnow go throughinclude_jpeglib.h, ensuring consistent type definitions across all translation unitsFixes
Closes #128